// import { Page } from "@/types/storeModule"
import { assign, cloneDeep } from 'lodash-es'

const state = {
	// 接口调用参数
	params: {
		page: {
			currentPage: 1,
			pageSize: 20,
			totalCount: 0,
			totalPage: 0,
			sortField: 'id',
			order: 'desc'
		},
		options: {}
	},
	roles: {}, // 权限
	apiName: 'surveyTemplate',
	privileges: [
		'admin-survey-template-add',
		'admin-survey-template-export',
		'admin-survey-template-remove'
	],
	// 列表data数据
	isLoading: false,
	tableData: [],
	searchData: [
		{
			id: 'entity.nameCn',
			name: '名称(ZH)',
			type: 'text',
			hint: '名称(ZH)',
			defaultValue: ''
		}
	],
	tableHeadList: [
		{
			label: '名称(ZH)',
			prop: 'nameZh',
			width: 80
		},
		{
			label: '名称(EN)',
			prop: 'nameEn',
			width: 80
		},
		{
			label: '标题图链接',
			prop: 'headerImg',
			width: 200
		},
		{
			label: '标题描述',
			prop: 'headerDesc',
			width: 200
		},
		{
			label: '反馈描述',
			prop: 'feedbackDesc',
			width: 200
		},
		{
			label: '尾部描述',
			prop: 'footerDesc',
			width: 200
		}
	]
}

// getters
const getters = {}

// actions
const actions = {}

// mutations
const mutations = {
	// 更新页面搜索内容
	updateSearchData(state, payload: any[]) {
		state.searchData = payload
	},
	// 更新表格 loading 状态
	updateLoading(state, payload: boolean) {
		state.isLoading = payload
	},

	// 更新数据page
	updatePage(state, payload: any) {
		state.params.page = assign(state.params.page, payload)
	},

	// 更新数据Condition
	updateCondition(state, payload: any) {
		state.params.condition = cloneDeep(payload)
	},

	// 更新data数据
	updateTableData(state, payload: any[]) {
		state.tableData = payload
	},
	// 更新列表表头数据
	updateEditTableList(state, payload: any[]) {
		state.tableHeadList = payload
	},
	// 更新列表参数数据
	updateParams(state, payload: any) {
		state.params = Object.assign({}, state.params, payload)
	},
	// 更新权限
	updateRoles(state, payload: Record<string, boolean>) {
		state.roles = payload
	}
}

export default {
	namespaced: true,
	state,
	getters,
	actions,
	mutations
}
